const KEY = 'app_status'

const init = () => {
    const setting = localStorage.getItem(KEY)
    if (!setting) {
        localStorage.setItem(KEY, JSON.stringify({}))
    }
}

const sidebarStatusKey = 'sidebar_status'
export const getSidebarStatus = () => {
    init()
    const setting = JSON.parse(localStorage.getItem(KEY) as string)
    const status: undefined | boolean = setting[sidebarStatusKey]
    return status === undefined ? true : !!status
}

export const setSidebarStatus = (newStatus: boolean) => {
    init()
    const setting = JSON.parse(localStorage.getItem(KEY) as string)
    setting[sidebarStatusKey] = newStatus
    localStorage.setItem(KEY, JSON.stringify(setting))
}
